<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>计算器</title>
	</head>
	<body>
		<p>第一个数</p>
		<input id="first" type="number" />
		<p>第二个数</p>
		<input id="second" type="number" />
		<p>运算：1加，2减，3乘，4除</p>
		<input id="yunsuan" type="number" max="4" min="1" />
		<p>按下后计算</p>
		<input id="jisuan" type="button" value="计算" onclick="suan()"/>
		<p>结果</p>
		<input id="resultnum" type="text" readonly width="20%" />
		<script type="text/javascript">
			var a=document.getElementById("first");
			var b=document.getElementById("second");
			var c=document.getElementById("yunsuan");
			var result;
			
			function suan()
			{
				var resultObj = document.getElementById("resultnum");
				if (parseInt(c.value)==1)
				{
					resultObj.value=parseInt(a.value) + parseInt(b.value);
				}
				if(parseInt(c.value)==2)
				{
					resultObj.value=parseInt(a.value) - parseInt(b.value);
				}
				if(parseInt(c.value)==3)
				{
					resultObj.value=parseInt(a.value) * parseInt(b.value);
				}
				if(parseInt(c.value)==4)
				{
					resultObj.value=parseInt(a.value) / parseInt(b.value);
				}
			}
		</script>
	</body>
</html>